﻿using HY.Model;
using HY.Service;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System.Linq.Expressions;

namespace HY.Web.Controllers
{
    public class SysLogController : BaseController
    {
        public SysLogController(ILogger<SysLogController> logger) : base(logger)
        {
        }
        [Authorize]
        public IActionResult Index()
        {
            return View();
        }
        [Authorize]
        [HttpPost]
        public IActionResult Index(SysLog model, int pageIndex, int pageSize)
        {
            Expression<Func<SysLog, bool>> filter = e => true;
            //if (RoleId == 0)
            //{
            //    if (!string.IsNullOrEmpty(model.UserName))
            //        filter = filter.And(c => c.UserName.Contains(model.UserName));
            //}
            //else
            //    filter = filter.And(c => c.UserName == UserName);
            if (!string.IsNullOrEmpty(model.TableName))
                filter = filter.And(c => c.TableName == model.TableName);
            if (!string.IsNullOrEmpty(model.OpeType))
                filter = filter.And(c => c.OpeType.Contains(model.OpeType));
            if (!string.IsNullOrEmpty(model.OpeResult))
                filter = filter.And(c => c.OpeResult == model.OpeResult);
            if (!string.IsNullOrEmpty(model.OpeDetail))
                filter = filter.And(c => c.OpeDetail.Contains(model.OpeDetail));
            if (!string.IsNullOrEmpty(model.Remark))
                filter = filter.And(c => c.Remark.Contains(model.Remark));
            if (model.AddTime != null)
                filter = filter.And(c => c.AddTime >= model.AddTime);
            if (model.UpdateTime != null)
                filter = filter.And(c => c.AddTime <= model.UpdateTime.Value.AddDays(1));
            int totalCount = 0;
            var data = DbContext.db.Queryable<SysLog>().Where(filter).OrderBy(it => it.Id, OrderByType.Desc).ToPageList(pageIndex, pageSize, ref totalCount);
            return Json(Success(totalCount, data));
        }
    }
}